import http from "../utils/request";

import { SearchBooking } from "../pages/booking-manage";
import dayjs from "dayjs";

export const getBookingList = (searchBooking: SearchBooking, pageNo: number, pageSize: number)=>{
    // 1.将日期格式转化为后台需要的时间戳
    let bookingTimeRangeStart;
    let bookingTimeRangeEnd;
    if(searchBooking.rangeStartDate && searchBooking.rangeStartTime) {
        const rangStartDateStr = dayjs(searchBooking.rangeStartDate).format("YYYY-MM-DD");
        const rangStartTimeStr = dayjs(searchBooking.rangeStartTime).format("HH:mm");
        bookingTimeRangeStart = dayjs(`${rangStartDateStr} ${rangStartTimeStr}`).valueOf();
    }
    if(searchBooking.rangeEndDate && searchBooking.rangeEndTime) {
        const rangEndDateStr = dayjs(searchBooking.rangeEndDate).format("YYYY-MM-DD");
        const rangEndTimeStr = dayjs(searchBooking.rangeEndTime).format("HH:mm");
        bookingTimeRangeEnd = dayjs(`${rangEndDateStr} ${rangEndTimeStr}`).valueOf();
    }

    return http.get('/booking/list', {
        params: {
            username: searchBooking.username,
            meetingRoomName: searchBooking.meetingRoomName,
            meetingRoomPosition: searchBooking.meetingRoomPosition,
            bookingTimeRangeStart,
            bookingTimeRangeEnd,
            pageNo,
            pageSize
        }
    })
}

export const apply = (id: number)=>{
    return http.get('/booking/apply' + id)
}

export const reject = (id: number)=>{
    return http.get('/booking/reject' + id)
}

export const unbind = (id: number)=>{
    return http.get("/booking/unbind" + id)
}